import { Duplex } from 'stream'
/* export const setHeader = function (res, code = 200, header = {
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Headers': 'Content-Type',
  'Access-Control-Allow-Methods': 'GET',
  'Content-type': 'text/html; charset=UTF-8'
}) {
  res.writeHead(code, header)
} */
export default function createResponse() {
  const response = Duplex()
  response._read = function (chunk, encoding, next) {
    console.log(chunk)
    // this.push('_read')
    /* this._readNum = this._readNum || 0
    if (this._readNum > 1) {
      this.push(null)
    } else {
      this.push('' + (this._readNum++))
    } */
  }
  response._write = function (buf, enc, next) {
    // a, b
    process.stdout.write('_write ' + buf.toString() + '\n')
    next()
  }
  response.on('data', buf => {
    process.stdout.write(buf)
  })
  response.on('end',function(){
    console.log('end')
  })
  response.end()
  return response
}